#ifndef __FSAPI_H__
#define __FSAPI_H__

#include "lfs.h"
#include "typedef.h"

enum fs_open_flags {
    // open flags
    FS_O_RDONLY = 1,        // Open a file as read only
    FS_O_WRONLY = 2,        // Open a file as write only
    FS_O_RDWR   = 3,        // Open a file as read and write
    FS_O_CREAT  = 0x0100,   // Create a file if it does not exist
    FS_O_EXCL   = 0x0200,   // Fail if a file already exists
    FS_O_TRUNC  = 0x0400,   // Truncate the existing file to zero size
    FS_O_APPEND = 0x0800,   // Move to end of file on every write
};

// File seek flags
enum fs_whence_flags {
    FS_SEEK_SET = 0,   // Seek relative to an absolute position
    FS_SEEK_CUR = 1,   // Seek relative to the current file position
    FS_SEEK_END = 2,   // Seek relative to the end of the file
};

#define FS_FILE_NAME_MAX 50
#define FS_FILE_NAME_CNT 4;

typedef lfs_file_t fs_fd;

void fs_init(void);
int fs_open(fs_fd *fd, const char *path, unsigned int mode);
int fs_write(fs_fd *fd, char *buf, int len);
int fs_read(fs_fd *fd, char *buf, int len);
int fs_read_line(fs_fd *fd, char *buf, int len);
int fs_truncate(fs_fd *fd, int len);
int fs_delete(const char *path);
int fs_close(fs_fd *fd);
int fs_exist(const char *path);
int fs_lseek(fs_fd *fd, int pos, int mode);
int fs_size(fs_fd *fd);
int fs_rename(char *old_path, char *new_path);
int fs_sync(fs_fd *fd);

int fs_ls(const char_t *path);
int fs_cat(const char *name);
int fs_mkdir(const char *path);
int fs_file_list(const char_t *path, char_t *name_list, int32_t name_len, int32_t cnt);
int fs_format(void);

#endif
